Skip to content

[Repo Assist] fix: prevent duplicate test ID crash for xUnit MemberData; improve theory name parsing; add TypeCheck build target#2156

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-duplicate-test-ids-2126-1682f0570a8b1e32
Draft

[Repo Assist] fix: prevent duplicate test ID crash for xUnit MemberData; improve theory name parsing; add TypeCheck build target#2156
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-duplicate-test-ids-2126-1682f0570a8b1e32

Conversation

@github-actions
Copy link
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Closes #2126 (the "An item with the same key has already been added" crash for xUnit MemberData tests — works alongside draft PR #2127 which addresses InlineData float parameters).

Changes

1. ArrayExt.venn — defensive deduplication guard

venn builds Dictionary maps from test IDs. If two TestItemDTO entries resolve to the same ID (as happens with MemberData theory tests when xUnit generates no unique display name), the dict |> Dictionary construction throws:

Error: An item with the same key has already been added.
Key: c:\Tests.fsproj -- MyTests+multiply.Returns expected value

Fix: add Array.distinctBy before building each map. This silently drops duplicates rather than crashing, so the remaining test items are still shown and runnable.

2. TestItemDTO.getFullname_withNestedParamTests — safer XUnit theory fragment extraction

The old approach used dto.DisplayName.Split('.') |> Array.last. For display names like
"MyModule.Returns expected value ({ Multiplicand = 0.5; ExpectedValue = 1.0 })" this yields "0 })" — wrong, and a duplicate key if multiple cases share the same tail fragment.

Fix: when DisplayName starts with FullName, use Substring(FullName.Length) to extract the parameter fragment without splitting on interior dots. This matches the approach in draft PR #2127 (by GitHub Copilot) and extends it to the MemberData case where the xUnit display name includes field values with decimal points.

3. build/Program.fs — new TypeCheck FAKE target

Adds a TypeCheck target that runs Fable compilation only (no webpack bundling). This is faster than the full Build target and is useful as a quick type-correctness check in development or lightweight CI scenarios.

dotnet run --project build -- -t TypeCheck

Root Cause

xUnit's VSTest adapter does not include theory case parameters in FullyQualifiedName (FullName). For [(InlineData)] tests, xUnit appends the parameter values to DisplayName; for [(MemberData)] tests the parameter objects are serialised via their ToString(). When ToString() values contain dots (e.g. F# records with float fields), the old Split('.') |> Array.last heuristic produces wrong/duplicate fragments. The venn crash is a secondary consequence of identical IDs entering the test tree.

Test Status

Fable compilation (dotnet fable src --noCache) — no new errors or warnings.
Build script compilation (dotnet build build/build.fsproj) — no errors.

No automated test suite exists. The fix is manually verifiable by creating an xUnit project with [(MemberData)] theory tests using F# records as test data and confirming the Test Explorer no longer crashes on refresh.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@d1d884596e62351dd652ae78465885dd32f0dd7d

…TypeCheck build target

- In ArrayExt.venn, add Array.distinctBy guards before building the ID
  maps to prevent 'An item with the same key has already been added'
  exceptions when xUnit MemberData theory tests produce duplicate IDs
  (Closes #2126, works alongside PR #2127)

- In TestItemDTO.getFullname_withNestedParamTests for XUnit, replace the
  Split('.') |> Array.last approach with Substring(FullName.Length). This
  correctly handles float parameters like 0.5 in InlineData and parameter
  records in MemberData that contain dots in their ToString output.

- Add a TypeCheck FAKE target to build/Program.fs that runs Fable
  compilation only (no webpack bundling), providing faster type-checking
  feedback in development and CI scenarios.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with xUnit Test Explorer test names in VS Code with F#.

0 participants